package hn.cch.framework.excel;

import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.event.SyncReadListener;
import hn.cch.framework.excel.entity.EasyExcelReadEntity;
import org.junit.Assert;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.InputStream;
import java.util.List;

public class EasyExcelReadTest {

    private static final Logger logger = LoggerFactory.getLogger(EasyExcelReadTest.class);

    public String excel_path = "src/main/resources/excel";
    @Test
    public void testRead1() {

        try (InputStream inputStream = ClassLoader.getSystemClassLoader()
                .getResourceAsStream("excel/easy_excel_read.xlsx")) {
            // 按列读取
            List<EasyExcelReadEntity> readList = EasyExcel.read(inputStream,
                            EasyExcelReadEntity.class, new SyncReadListener())
                    .sheet() // 设置sheet页
                    .headRowNumber(2) // 设置表头行数
                    .doReadSync();
            Assert.assertEquals(readList.size(), 3);
        } catch (Exception e) {
            logger.error(e.getMessage());
        }


    }

}
